package com.cuit.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @author cfy
 * @date 2022/11/21 21:23
 * @desciption: mybatisPlus配置
 */
@EnableTransactionManagement  // 开启事务
@MapperScan("com.cuit.mapper")
@Configuration
public class MybatisPlusConfig {

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        // 定义拦截器
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // 定义分页插件
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor()); // 定义一个分页的插件
        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor()); // 定义一个乐观锁
        return interceptor;
    }
}
